﻿var gWPageIndex = 1;

function pageLoad(sender, args) 
{
    if(typeof($("commentPage")) != "undefined")
    {
        RendPageNavigator(comPage,"commentPage","GetPage");
    }
     
}
function erclose()
{
    if($("valContent").style.display=="")
    {
        $("valContent").style.display='none';
    }
}
//添加小黑板信息
function AddComm()
{
    if($("txtCommInput").value=="")
    {
        $("valContent").style.display=''; 
        return;
    }
    $("btnCommInput").disabled=true;
    showProgressBar(true);
    if(Memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }    
    var con=$("txtCommInput").value.replace(/<script[^>]*>([\u0001-\uFFFF]*?)<\/script>/gi,"");
    if(con.length>2000) con=con.substring(0,2000);
    WebServices.My.AddGetComment(Memberno,1,gWLastCount,con,onsuccAc);    
}
//初始化添加小黑板的数据
function onsuccAc(result)
{
    showProgressBar(false);
    $("btnCommInput").disabled=false;
    if(result!=null&&result[0]==1)
    {
        $("txtCommInput").value="";
        if(IsView==1)
        {
            RendComList(result[1],"CommentList");
            RendPageNavigator(result[2],"commentPage","GetPage");
        }
    }     
}

//通过页面得到小黑板上面的留言
function GetAllComment(pageIndex,pageCount)
{
    WebServices.My.GetAllComment(Memberno,pageIndex,pageCount,onsucc);
}
//初始化小黑板数据
function onsucc(result)
{
   RendComList(result[1],"CommentList");
   RendPageNavigator(result[0],"commentPage","GetPage");
   showProgressBar(false);
}
//得到页面数据
function GetPage(pageIndex)
{
    gDPageIndex = pageIndex;
    showProgressBar(true);    
    GetAllComment(gDPageIndex,gWLastCount);
}
//替换小黑板上面的信息
function RendComList(list,divID)
{
    var domDiv1 = $(divID);   
    if(domDiv1!=null)
    {
        if(Sys.UI.DomElement.containsCssClass(domDiv1, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv1, "DisplayNone");
        }
        if($("CommentTemplate")==null) return;
        var item= $("CommentTemplate").innerHTML;
        var listBuilder = new Sys.StringBuilder();
        for (var index = 0; index < list.length; ++index) 
        {
            var obj = list[index];
            var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.avatar==""?"/Images/No_pic.gif":obj.avatar)+"\"/>");
            tmp = tmp.replace(/\$NickName\$/gi,obj.nickname);
            tmp = tmp.replace(/\$userFrom\$/gi,obj.userFrom);
            tmp = tmp.replace(/\$content\$/gi,EncodeMessage(obj.content));
            tmp = tmp.replace(/\$CreateDate\$/gi,GetFormatDate(gDateFormat,gStrDate2,obj.DiffDate));           
            listBuilder.append(tmp);
        }
        domDiv1.innerHTML = listBuilder.toString();
   }
}
 if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();